import os
import re


def renameall():
	file_name = '/home/hlf/code/code_LSTM+CNN/data_set/hours_2021.6.8_2022.5.31/img'
	filelist = sorted(os.listdir(file_name))
	re_str_1 = '^[0-9]{4}.[0-9]{1}.[0-9]{1}-(.*?)$'
	re_str_2 = '^[0-9]{4}.[0-9]{2}.[0-9]{1}-(.*?)$'
	for o_name in filelist:
		if re.search(re_str_1, o_name):
			o_name_list = list(o_name)
			o_name_list.insert(7, '0')
			new_name = ''.join(o_name_list)
			os.rename(file_name + '/' + o_name, file_name + '/' + new_name)
			print(o_name, new_name)
		if re.search(re_str_2, o_name):
			o_name_list = list(o_name)
			o_name_list.insert(8, '0')
			new_name = ''.join(o_name_list)
			os.rename(file_name + '/' + o_name, file_name + '/' + new_name)
			print(o_name, new_name)


if __name__ == '__main__':
	renameall()
	print('hh')